package com.gwaeron.game;

public class StatTracker {

	//omg singleton!
	private static StatTracker single = new StatTracker();
	private static int daysPlayed;
	private static int hoursPlayed;
	private static int minutesPlayed;
	private static int secondsPlayed;
	
	public static StatTracker get(){
		return single;
	}
	
	{new GameTimer();}
	
	public int getDaysPlayed(){
		return daysPlayed;
	}
	
	public int getHoursPlayed(){
		return hoursPlayed;
	}
	
	public int getMinutesPlayed(){
		return minutesPlayed;
	}
	
	public int getSecondsPlayed(){
		return secondsPlayed;
	}
	
	public static void pauseTimer(){
		
	}
	
	public static void resumeTimer(){
		
	}
	
	
	
	private class GameTimer extends Thread{
		long startTime;
		protected GameTimer(){
			secondsPlayed = minutesPlayed = hoursPlayed = daysPlayed = 0;
			this.startTime = System.currentTimeMillis();
			start();
		}
		
		public void run(){
			while(true)
			try {
				Thread.sleep(1000);
				secondsPlayed = (int)((System.currentTimeMillis() - startTime) / 1000)%60;
				minutesPlayed = (int)(((System.currentTimeMillis() - startTime)/1000)/60)%60;
				hoursPlayed = (int)(((System.currentTimeMillis()-startTime)/1000)/3600)%24;
				daysPlayed = (int)(((System.currentTimeMillis()-startTime)/1000)/3600)/24;
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				
			}
		}
	}

}

